
#include "DemoMenu.h"

DemoMenu::DemoMenu(void)
{
}

DemoMenu::~DemoMenu(void)
{
}

void DemoMenu::show() const
{	
    using std::cout;
    using std::ends;

    system("cls");
    cout << "1. Demo No.1\n"
		 << "2. Demo Conveyer Belt\n"
         << "3. Gun\n"
         << "4. Straight Line.\n"
         << "5. Double Straight Line\n"
         << "6. Rectangle\n"
         << "B. Back to Main Menu.\n"
		 << "------------------------\n"
		 << "Your choice: "
		 << ends;
}

void DemoMenu::keyboardListener(char const& key)
{
    switch (key)
    {
    case '1':
        MessageArray::Instance()->postMessage(SHOW_DEMO_ONE);
        break;
    case '2':
        MessageArray::Instance()->postMessage(SHOW_DEMO_CONVEYER_BELT);
        break;
    case '3':
        MessageArray::Instance()->postMessage(SHOW_DEMO_GUN);
        break;
    case '4':
        MessageArray::Instance()->postMessage(SHOW_DEMO_STRLINE);
        break;
    case '5':
        MessageArray::Instance()->postMessage(SHOW_DEMO_DSTRLINE);
        break;
    case '6':
        MessageArray::Instance()->postMessage(SHOW_DEMO_RECTANGLE);
        break;
    default:
        MessageArray::Instance()->postMessage(SHOW_MAINMENU);
        setFocus(false);
        break;
    }
}

bool DemoMenu::fire()
{
    U_MESSAGE msg(MessageArray::Instance()->getMessage());
    switch (msg)
    {
    case SHOW_DEMOMENU:
        setFocus(true);
        show();
        return true;
        break;
    default:
        if (getFocus())
        {
            keyboardListener(static_cast<char>(msg));
            return true;
        }
        break;
    }
    return false;
}
